<!DOCTYPE html>
<html>

{include file='public/header'}

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">用户管理</a>
            <a><cite>菜单管理</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <table id="menu" lay-filter="menu"></table>
    </div>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
        </div>
    </script>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        let params = {
            elem: '#menu'
            , toolbar: '#toolbarDemo'
            , url: '/admin/menu/list' //数据接口
            , id: 'menu'
            , limit: 99999
            , page:false
            , cols: [[ //表头
                { field: 'id', title: 'ID', width: 80, sort: true }
                , { field: 'title_show', title: '名称', }
                , { field: 'path', title: '路径', }
                , { field: 'sort', title: '排序', }
                , {
                    field: 'hide', title: '状态', templet: function (d) {
                        return d.hide == 0 ? '显示' : '隐藏'
                    }
                }
                , { toolbar: '#tbBar', title: '操作', width: 150 }
            ]]
            , response: {
                statusCode: 200 //规定成功的状态码，默认：0
            }
        }
        tableList(params)
        layui.use('table', function () {
            var table = layui.table;
            table.on('toolbar(menu)', function (obj) {
                var event = obj.event;
                if (event === 'add') {
                    x_admin_show('添加菜单', './info.html', 650, 500);
                }
            });
            table.on('tool(menu)', function (obj) {
                var event = obj.event;
                if (event === 'del') {
                    DeleteAjax('/admin/menu/delete',{ id: obj.data.id },'menu')
                } else if (event === 'edit') {
                    x_admin_show('编辑菜单', `./info.html?id=${obj.data.id}&pid=${obj.data.pid}`, 650, 500);
                }
            });

        });

    </script>
</body>

</html>